package student_system.Controller;

import student_system.Dao.studentDao;
import student_system.bean.student;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/add")
public class studentadd extends HttpServlet {
    studentDao dao=new studentDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPost(req, resp);
        req.setCharacterEncoding("utf-8");
        String snoStr=req.getParameter("sno");
        int sno=0;
        try {
            sno = Integer.parseInt(snoStr);
        } catch (Exception e) {
            //return null;
        }
        String sname=req.getParameter("sname");
        String sex=req.getParameter("sex");
        String birthday=req.getParameter("birthday");
        String dno=req.getParameter("dno");
        dao.addstudent(sno,sname,sex,birthday,dno);
        List<student> list=dao.testArrayList();
        req.setAttribute("lists",list);
        RequestDispatcher dispatcher =req.getRequestDispatcher("StudentInfoSelect_3.jsp");
        dispatcher.forward(req,resp);

    }
}
